package presentation;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

public class PlaceOrderDialog extends JDialog {
	/**
	 * @uml.property  name="okButton"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JButton okButton;
	/**
	 * @uml.property  name="phoneField"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JTextField phoneField;
	/**
	 * @uml.property  name="cityField"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JTextField cityField;
	/**
	 * @uml.property  name="zipCodeField"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JTextField zipCodeField;
	/**
	 * @uml.property  name="addressField"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JTextField addressField;

	public PlaceOrderDialog() {
		setTitle("Place Order");
		setLayout(new GridBagLayout());
		GridBagConstraints constraints = new GridBagConstraints();
		constraints.insets = new Insets(5,10,5,10);
		
		constraints.gridx = 0;
		constraints.gridy = 0;
		constraints.fill = GridBagConstraints.HORIZONTAL;
		JLabel address = new JLabel("Address:");
		address.setHorizontalAlignment(JLabel.RIGHT);
		add(address, constraints);
		
		constraints.gridx = constraints.gridx + 1;
		constraints.gridwidth = 2;
		constraints.weightx = 0.1;
		addressField = new JTextField();
		add(addressField,constraints);
		constraints.gridwidth = 1;
		constraints.fill = GridBagConstraints.NONE;
		constraints.weightx = 0;
		
		constraints.gridx = 0;
		constraints.gridy = constraints.gridy + 1;
		constraints.fill = GridBagConstraints.HORIZONTAL;
		JLabel zipCode = new JLabel("Zipcode:");
		zipCode.setHorizontalAlignment(JLabel.RIGHT);
		add(zipCode, constraints);
		zipCodeField = new JTextField();
		constraints.gridx = constraints.gridx + 1;
		constraints.gridwidth = 2;
		constraints.weightx = 0.1;
		add(zipCodeField,constraints);
		constraints.gridwidth = 1;
		constraints.fill = GridBagConstraints.NONE;
		constraints.weightx = 0;
		
		constraints.gridx = 0;
		constraints.gridy++;
		constraints.fill = GridBagConstraints.HORIZONTAL;
		JLabel city = new JLabel("City:");
		city.setHorizontalAlignment(JLabel.RIGHT);
		add(city, constraints);
		cityField = new JTextField();
		constraints.gridx = constraints.gridx + 1;
		constraints.gridwidth = 2;
		constraints.weightx = 0.1;
		add(cityField,constraints);
		constraints.gridwidth = 1;
		constraints.fill = GridBagConstraints.NONE;
		constraints.weightx = 0;
		
		constraints.gridx = 0;
		constraints.gridy++;
		constraints.fill = GridBagConstraints.HORIZONTAL;
		JLabel phone = new JLabel("Phone #:");
		phone.setHorizontalAlignment(JLabel.RIGHT);
		add(phone, constraints);
		phoneField = new JTextField();
		constraints.gridx = constraints.gridx + 1;
		constraints.gridwidth = 2;
		constraints.weightx = 0.1;
		add(phoneField,constraints);
		constraints.gridwidth = 1;
		constraints.fill = GridBagConstraints.NONE;
		constraints.weightx = 0;
		
		JRadioButton sendToAll = new JRadioButton("Send to all");
		JRadioButton sendToClosest = new JRadioButton("Send to closest");
		ButtonGroup group = new ButtonGroup();
		group.add(sendToAll);
		group.add(sendToClosest);
		constraints.gridx = 1;
		constraints.gridy++;
		add(sendToAll,constraints);
		
		constraints.gridx = 2;
		add(sendToClosest,constraints);
		
		JPanel buttonPanel = new JPanel();
		okButton = new JButton("OK");
		
		JButton cancelButton = new JButton("Cancel");
		cancelButton.addActionListener(new ActionListener() {
		
			public void actionPerformed(ActionEvent arg0) {
				cancelButtonActionPerformed();
			}
		});
		
		buttonPanel.add(okButton);
		buttonPanel.add(cancelButton);
		constraints.gridy++;
		constraints.gridx = 1;
		constraints.gridwidth = 2;
		add(buttonPanel,constraints);
		
		pack();
	}

	protected void cancelButtonActionPerformed() {
		this.setVisible(false);
		this.dispose();
	}
	
	public void addOKButtonActionListener(ActionListener actionListener){
		okButton.addActionListener(actionListener);
	}
	

	public String getPhoneNumber() {
		return phoneField.getText();
	}

	public String getCity() {
		return cityField.getText();
	}

	public String getZipCode() {
		return zipCodeField.getText();
	}

	public String getAddress() {
		return addressField.getText();
	}
	
}
